home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / app / BaseUndoManager.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  2.4 KB  |  103 lines

  1. package com.extensibility.app;
  2.  
  3. import javax.swing.undo.CompoundEdit;
  4. import javax.swing.undo.UndoManager;
  5. import javax.swing.undo.UndoableEdit;
  6.  
  7. public class BaseUndoManager extends UndoManager {
  8.    UndoAction undoAction = new UndoAction(this, "edit.item.undo", 90);
  9.    RedoAction redoAction;
  10.    UndoableEdit milestone;
  11.    boolean milestoneBlocksUndo = false;
  12.  
  13.    public BaseUndoManager() {
  14.       this.undoAction.setEnabled(false);
  15.       this.redoAction = new RedoAction(this, "edit.item.redo", 68);
  16.       this.redoAction.setEnabled(false);
  17.    }
  18.  
  19.    public boolean addEdit(UndoableEdit var1) {
  20.       boolean var2 = super.addEdit(var1);
  21.       if (var2) {
  22.          this.undoAction.updateUndoState();
  23.          this.redoAction.updateRedoState();
  24.       }
  25.  
  26.       return var2;
  27.    }
  28.  
  29.    public void discardAllEdits() {
  30.       super.discardAllEdits();
  31.       this.undoAction.setEnabled(false);
  32.       this.redoAction.setEnabled(false);
  33.    }
  34.  
  35.    public BaseAction getUndoAction() {
  36.       return this.undoAction;
  37.    }
  38.  
  39.    public BaseAction getRedoAction() {
  40.       return this.redoAction;
  41.    }
  42.  
  43.    public void trimUndoneEdits() {
  44.       UndoableEdit var1 = ((UndoManager)this).editToBeRedone();
  45.       if (var1 != null) {
  46.          ((UndoManager)this).trimEdits(super.edits.lastIndexOf(var1), super.edits.lastIndexOf(((CompoundEdit)this).lastEdit()));
  47.       }
  48.  
  49.       this.redoAction.updateRedoState();
  50.    }
  51.  
  52.    public void undo() {
  53.       UndoableEdit var1 = ((UndoManager)this).editToBeUndone();
  54.       if (var1 == this.milestone) {
  55.          this.clearMilestone();
  56.       }
  57.  
  58.       super.undo();
  59.    }
  60.  
  61.    public boolean canUndo() {
  62.       return this.milestone != null && this.milestoneBlocksUndo && this.milestone == ((UndoManager)this).editToBeUndone() ? false : super.canUndo();
  63.    }
  64.  
  65.    public void setMilestone(boolean var1) {
  66.       this.milestone = ((UndoManager)this).editToBeUndone();
  67.       this.milestoneBlocksUndo = var1;
  68.       if (var1) {
  69.          this.undoAction.updateUndoState();
  70.       }
  71.  
  72.    }
  73.  
  74.    public void clearMilestone() {
  75.       this.milestone = null;
  76.       if (this.milestoneBlocksUndo) {
  77.          this.undoAction.updateUndoState();
  78.       }
  79.  
  80.       this.milestoneBlocksUndo = false;
  81.    }
  82.  
  83.    public void trimEditsSinceMilestone() {
  84.       if (this.milestone != null) {
  85.          int var1 = super.edits.lastIndexOf(this.milestone) + 1;
  86.          int var2 = super.edits.lastIndexOf(((CompoundEdit)this).lastEdit());
  87.          if (var1 <= var2) {
  88.             ((UndoManager)this).trimEdits(var1, var2);
  89.          }
  90.       }
  91.  
  92.    }
  93.  
  94.    public void undoToMilestone() {
  95.       if (this.milestone != null) {
  96.          while(((UndoManager)this).editToBeUndone() != this.milestone) {
  97.             this.undo();
  98.          }
  99.       }
  100.  
  101.    }
  102. }
  103.